package io.github.maojian.sort;

import org.junit.Test;

import java.util.Arrays;

/**
 * @Auther: jian.mao
 * @Date: 2022-06-28 09:11
 * @Description: https://leetcode.cn/problems/wiggle-sort-ii/
 */
public class Q324 {
    public void wiggleSort(int[] nums) {
        int[] arr = nums.clone();
        Arrays.sort(arr);
        int n = nums.length;
        int x = (n + 1) / 2;
        for (int i = 0, j = x - 1, k = n - 1; i < n; i += 2, j--, k--) {
            nums[i] = arr[j];
            if (i + 1 < n) {
                nums[i + 1] = arr[k];
            }
        }
    }

    @Test
    public void test() {
        int[] nums = new int[]{1, 2, 1, 3, 2, 3};
        wiggleSort(nums);
        Arrays.stream(nums).forEach(System.out::print);
    }
}
